home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / ctlib100.zip / INSTALL.LZH / LISTBOX.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-12  |  4KB  |  135 lines

  1. {**************************************************************************}
  2. {*  BitSoft Development, L.L.C.                                           *}
  3. {*  Copyright (C) 1995, 1996 BitSoft Development, L.L.C.                  *}
  4. {*  All rights reserved.                                                  *}
  5. {**************************************************************************}
  6.  
  7. unit ListBox;
  8.  
  9. {$X+}
  10.  
  11. interface
  12.  
  13. uses Dialogs,
  14.      Containr, ctCollec, ctListBx;
  15.  
  16. type
  17.   ListBoxTypes = (lbSequenceListBox, lbSortedSequenceListBox);
  18.   { Variables of ListBoxTypes are used with the test procedures in this
  19.     unit. }
  20.  
  21. type
  22.   PTestListBoxDlg = ^TTestListBoxDlg;
  23.   TTestListBoxDlg = object(TDialog)
  24.       ListBox : PSequenceListBox;
  25.     constructor Init (ListBoxType : ListBoxTypes);
  26.   end;  { TTestListBoxDlg }
  27.  
  28. procedure TestSequenceListBox (ListBoxType : ListBoxTypes);
  29.  
  30. implementation
  31.  
  32. uses App, Objects, Drivers, Views,
  33.      BsdProcs,
  34.      Types;
  35.  
  36. {****************************************************************************}
  37. { TTestListBoxDlg object                                                     }
  38. {****************************************************************************}
  39. {****************************************************************************}
  40. { TTestListBoxDlg.Init                                                       }
  41. {****************************************************************************}
  42. constructor TTestListBoxDlg.Init (ListBoxType : ListBoxTypes);
  43. var
  44.   R : TRect;
  45.   ATitle : TTitleStr;
  46.   HScrollBar, VScrollBar : PImsScrollbar;
  47.   Control : PView;
  48. begin
  49.   R.Assign(20, 3, 60, 20);
  50.   case ListBoxType of
  51.     lbSequenceListBox : ATitle := 'TSequenceListBox';
  52.     lbSortedSequenceListBox : ATitle := 'TSortedSequenceListBox';
  53.   end; { case }
  54.   if not TDialog.Init(R, ATitle) then
  55.      Fail;
  56.   R.Assign(37, 2, 38, 12);
  57.   VScrollBar := New(PImsScrollbar, Init(R));
  58.   Insert(VScrollbar);
  59.   R.Assign(2, 2, 37, 12);
  60.   case ListBoxType of
  61.     lbSequenceListBox :
  62.       ListBox := New(PSequenceListBox, Init(R, 2, VScrollbar));
  63.     lbSortedSequenceListBox :
  64.       ListBox := New(PSortedSequenceListBox, Init(R, 2, VScrollbar));
  65.   end; { case }
  66.   if ListBox = nil
  67.     then begin
  68.            TDialog.Done;
  69.            Fail;
  70.          end; { if }
  71.   Insert(ListBox);
  72.   R.Assign(1, 1, 8, 2);
  73.   Control := New(PLabel, Init(R, '~I~items', ListBox));
  74.   Insert(Control);
  75.   R.Assign(2, 12, 37, 13);
  76.   HScrollBar := New(PImsScrollbar, Init(R));
  77.   Insert(HScrollbar);
  78.   ListBox^.NewHScrollBar(HScrollBar);
  79.   R.Assign(2, 14, 12, 16);
  80.   Control := New(PButton, Init(R, 'O~k~', cmOk, bfDefault));
  81.   Insert(Control);
  82.   R.Assign(25, 14, 35, 16);
  83.   Control := New(PButton, Init(R, 'Cancel', cmCancel, bfNormal));
  84.   Insert(Control);
  85.   SelectNext(False);
  86. end;
  87.  
  88. {****************************************************************************}
  89. { NewSequence                                                                }
  90. {****************************************************************************}
  91. function NewSequence (MaxItems : LongInt; SortedSequence : Boolean) :
  92.   PSequence;
  93. var
  94.   Str : String;
  95.   S : PSequence;
  96.   i : LongInt;
  97. begin
  98.   if SortedSequence
  99.     then S := New(PStreamStringCollection, Init(MaxItems, 1))
  100.     else S := New(PStreamUnSortedStrCollection, Init(MaxItems, 1));
  101.   if S <> nil then
  102.     for i := 1 to MaxItems do
  103.     begin
  104.       FormatStr(Str,'Item %d',i);
  105.       S^.Insert(NewStr(Str));
  106.     end; { for }
  107.   NewSequence := S;
  108. end;
  109.  
  110. {****************************************************************************}
  111. { TestSequenceListBox                                                        }
  112. {****************************************************************************}
  113. procedure TestSequenceListBox (ListBoxType : ListBoxTypes);
  114. var
  115.   Rec : TSequenceListBoxRec;
  116.   Dialog : PDialog;
  117. begin
  118.   case ListBoxType of
  119.     lbSequenceListBox :
  120.       Rec.List := NewSequence(TotalDisplayItems, False);
  121.     lbSortedSequenceListBox :
  122.       Rec.List := NewSequence(TotalDisplayItems, True);
  123.   end; { case }
  124.   Rec.Selection := 0;
  125.   Dialog := New(PTestListBoxDlg, Init(ListBoxType));
  126.   if Application^.ValidView(Dialog) <> nil
  127.     then begin
  128.            Dialog^.SetData(Rec);
  129.            Desktop^.ExecView(Dialog);
  130.            Dispose(Dialog, Done);
  131.          end; { if }
  132.   DisposeObject(Rec.List);
  133. end;
  134.  
  135. end.